import getApiData, { getApisData, getInitData } from "@/services/cpasRequest";
import { onlineGetApiData, onlineGetApisData } from "@/services/onlineRequest";


export async function getZcbfInitializeData(params: {
    zcbfIDs: string
}) {
    const res = await getApiData('pm.zcbfInitializeList', {
        zcbfIDs: params.zcbfIDs
    });
    if (res.code === 0) {
        return Promise.resolve({
            data: res.data,
            success: true,
        });
    }
    return Promise.resolve({
        data: res.data,
        success: false,
    });
}

export async function getDataGridLookupList(params: {
    TEMPLETList: string;
    CWBBTXList: string;
    mbTypeList: string;
    // fourName: string;
}) {
    const paramsData = {
        apis: [
            {
                name: params.TEMPLETList,
                // 私用的参数
                params: {}
            },
            {
                name: params.CWBBTXList,
                // 私用的参数
                params: {}
            },
            {
                name: params.mbTypeList,
                // 私用的参数
                params: {}
            },
            // {
            //     name: params.fourName,
            //     // 私用的参数
            //     params: {}
            // }
        ],
        reload: true,
        // 公用的参数
        params: {}
    }
    const res = await getApisData(paramsData);
    const TEMPLETList = res.data[params.TEMPLETList]
    const resCWBBTXList = res.data[params.CWBBTXList]
    const resmbTypeList = res.data[params.mbTypeList]
    // const temp3 = res.data[params.fourName]
    if (res.ok && TEMPLETList.ok && resCWBBTXList.ok && resmbTypeList.ok) {
        return Promise.resolve({
            data: res.data,
            success: true,
        });
    }
    return Promise.resolve({
        data: res.data,
        success: false,
    });
}


export async function getZcbfInit(params: {
    zcbfid: string;
    DGMB: string
}) {
    const res = await getInitData({
        zcbfid: params.zcbfid,
        mbmc: params.DGMB
    });
    if (res.code === 0) {
        return Promise.resolve({
            data: res.data,
            success: true,
        });
    }
    return Promise.resolve({
        data: res.data,
        success: false,
    });
}

//插入本地sjxm_zcbf数据库  ZcbfAndUser pm.zcbfEdit
export async function getPeriodList(params: { dbName: string; zcbfID: string }) {
    const resApis = await onlineGetApiData('ljjx.pm.periodList', params);
    if (resApis.ok) {
        return Promise.resolve({
            data: resApis.data,
            success: true,
        });
    }
    return Promise.resolve({
        data: resApis.data,
        success: false,
    });
}



//插入本地sjxm_zcbf数据库  ZcbfAndUser pm.zcbfEdit
export async function pushZcbfInfoSQL(zcbfData: any) {
    const resApis = await onlineGetApiData('ljjx.pm.zcbfEditInfo', { zcbfDataS: zcbfData });
    if (resApis.ok) {
        return Promise.resolve({
            data: '云平台 组成部分信息更改成功！',
            success: true,
        });
    }
    return Promise.resolve({
        data: '云平台 组成部分信息更改失败！',
        success: false,
    });
}
